package com.lanswon.icc.common.core.page;


import lombok.Getter;

import java.io.Serializable;
import java.util.List;

/**
 * @Description
 * @Author zsw
 * @Date 2019/11/18 9:35
 * @Version V1.0
 **/
@Getter
public class Navigator<T> implements Serializable {
    private boolean next;
    private boolean previous;
    private Pagination page;
    private int totalPages;
    private int totalRowsAmount;
    private List<T> data;
    private int startRow;


    public Navigator(Pagination page, int totalRowsAmount,
                     List<T> data) {
        this.page = page;
        this.totalRowsAmount = totalRowsAmount;
        this.data = data;
        this.totalPages = (totalRowsAmount - 1) / page.getPageSize() + 1;
        if(this.page.getPageNum() > this.totalPages){
            this.page.setPageNum(this.totalPages);
        }
        if(data != null && data.size() != 0){
            this.next = page.getPageNum() < this.totalPages;
            this.previous = page.getPageNum() > 1;
        }else{
            this.next = false;
            this.previous = false;
        }
    }

    public int getStartRow() {
        return  page.getPageNum() > 0 ? (page.getPageNum() - 1) * page.getPageSize() : 0;
    }
}